import { nextTick, ref } from 'vue';

import { useWindowSizeFn } from '@/hooks/useWindowSizeFn';

export const useTableHeight = () => {
  const searchRef = ref<HTMLElement>();
  const searchHeight = ref(0);

  const handleSize = async () => {
    await nextTick();

    const height = searchRef.value ? searchRef.value.offsetHeight : 0;
    searchHeight.value = height + 16;
  };

  useWindowSizeFn<void>(handleSize, { immediate: true });

  return { searchRef, searchHeight };
};
